\hypertarget{class_connection}{
\section{Connection类参考}
\label{class_connection}\index{Connection@{Connection}}
}


连接类  




{\ttfamily \#include $<$connection.h$>$}

\subsection*{组合类型}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{struct_connection_1_1_____connection_info}{\_\-\_\-ConnectionInfo}
\end{DoxyCompactItemize}
\subsection*{公有类型}
\begin{DoxyCompactItemize}
\item 
enum \{ \par
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4a6ac87b5ad88277e855c7069c92c1a479}{CI\_\-MSG} =  0, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4a989319b5032ad18954665d76be3eb774}{CI\_\-FILENEW}, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4a4ff6e27604edfac1c02ccfcc2d9b283c}{CI\_\-FILESTARTSEND}, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4ad3d543e05399f24d0e3aa51125bfe256}{CI\_\-FILESENDCANCEL}, 
\par
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4aa0369367db1b811c01bce029a8f47d2a}{CI\_\-FILECONTENT}, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4ab1b973f17f2c75ba75ba03fbd5ba5ccc}{CI\_\-FILECLOSE}, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4a42c1f798607deead31db115c4a382b59}{CI\_\-FILEMD5}, 
\hyperlink{class_connection_acea45320bf437182b6df56d238f127d4a26d0ecb83471911a4f52faebbdca9da7}{CI\_\-FILEEND}
 \}
\begin{DoxyCompactList}\small\item\em ConInfo常量列表 \end{DoxyCompactList}\item 
typedef struct \hyperlink{struct_connection_1_1_____connection_info}{Connection::\_\-\_\-ConnectionInfo} \hyperlink{class_connection_a99cb53a80cd37966cc4f7e922c5f2ccc}{ConInfo}
\end{DoxyCompactItemize}
\subsection*{公有成员}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_connection_a9de94289ca6259f94ef6aeba3b134a77}{Connection} ()
\item 
\hyperlink{class_connection_ac5af327d034a807cbdd45cd93b8d4efc}{Connection} (const SOCKADDR\_\-IN \&newAddr, int newRecvfd=0)
\item 
\hyperlink{class_connection_a2e4352edf667bea83001569e9da8a24d}{$\sim$Connection} ()
\item 
bool \hyperlink{class_connection_a6338a92b3fc9db9d1c82f537aecd1c10}{compare} (const \hyperlink{class_connection}{Connection} \&cpCon)
\item 
bool \hyperlink{class_connection_ac8c5ffaeee6b7ac1ac3b4eb27a1f6193}{isExist} (const SOCKADDR\_\-IN \&cpAddr)
\item 
int \hyperlink{class_connection_a2ce3e68b2f6e09a86591b3fc8818fac3}{getRecvfd} ()
\item 
void \hyperlink{class_connection_a76abdfdf3ba06bb8bfbc95d8cc3e9d8b}{setRecvfd} (int newRecvfd)
\item 
int \hyperlink{class_connection_a3c0a490cbc7337b7dda84ef72f3b5632}{startCon} ()
\item 
int \hyperlink{class_connection_a4dbf656f9bb517b2effa9d40ff49eabd}{closeCon} ()
\item 
int \hyperlink{class_connection_a6fa2bc6d6be7049487cce4135c3657e6}{sendMsg} (const std::string msg)
\item 
int \hyperlink{class_connection_a02edd03264480bcfec195f88c65385c5}{addFileToSend} (const std::string \&filepath)
\item 
int \hyperlink{class_connection_a34ff84664e4b728d4f59947dd45788a2}{testConnect} ()
\item 
SOCKADDR\_\-IN \hyperlink{class_connection_a3c590179abcedd53b3bae4fd3046a374}{getSelfAddr} ()
\end{DoxyCompactItemize}
\subsection*{静态公有成员}
\begin{DoxyCompactItemize}
\item 
static void $\ast$ \hyperlink{class_connection_a9f3f51055f4c70eeef82a7ba68e85e97}{thread\_\-recv} (void $\ast$arg)
\item 
static void $\ast$ \hyperlink{class_connection_a3f7349a98ae89d34f50dfbe839e14a13}{thread\_\-sendfile} (void $\ast$arg)
\end{DoxyCompactItemize}


\subsection{详细描述}
连接类 

\hyperlink{connection_8h_source}{connection.h} \hyperlink{class_connection}{Connection} header

Lai \begin{DoxyDate}{日期}
July 8 2011
\end{DoxyDate}
This file is part of cute-\/transfer based cracker project, which released under the GNU GPL v2 or v3 (whichever you like) This project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 主要负责与不同客户之间的连接和通信。 

\subsection{成员类型定义文档}
\hypertarget{class_connection_a99cb53a80cd37966cc4f7e922c5f2ccc}{
\index{Connection@{Connection}!ConInfo@{ConInfo}}
\index{ConInfo@{ConInfo}!Connection@{Connection}}
\subsubsection[{ConInfo}]{\setlength{\rightskip}{0pt plus 5cm}typedef struct {\bf Connection::\_\-\_\-ConnectionInfo}  {\bf Connection::ConInfo}}}
\label{class_connection_a99cb53a80cd37966cc4f7e922c5f2ccc}
连接信息 

\subsection{成员枚举类型文档}
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4}{
\subsubsection[{"@0}]{\setlength{\rightskip}{0pt plus 5cm}anonymous enum}}
\label{class_connection_acea45320bf437182b6df56d238f127d4}


ConInfo常量列表 

\begin{Desc}
\item[枚举值: ]\par
\begin{description}
\index{CI\_\-MSG@{CI\_\-MSG}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-MSG@{CI\_\-MSG}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4a6ac87b5ad88277e855c7069c92c1a479}{
CI\_\-MSG}
\label{class_connection_acea45320bf437182b6df56d238f127d4a6ac87b5ad88277e855c7069c92c1a479}
}]消息 \index{CI\_\-FILENEW@{CI\_\-FILENEW}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILENEW@{CI\_\-FILENEW}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4a989319b5032ad18954665d76be3eb774}{
CI\_\-FILENEW}
\label{class_connection_acea45320bf437182b6df56d238f127d4a989319b5032ad18954665d76be3eb774}
}]文件新建 \index{CI\_\-FILESTARTSEND@{CI\_\-FILESTARTSEND}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILESTARTSEND@{CI\_\-FILESTARTSEND}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4a4ff6e27604edfac1c02ccfcc2d9b283c}{
CI\_\-FILESTARTSEND}
\label{class_connection_acea45320bf437182b6df56d238f127d4a4ff6e27604edfac1c02ccfcc2d9b283c}
}]文件开始传送 \index{CI\_\-FILESENDCANCEL@{CI\_\-FILESENDCANCEL}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILESENDCANCEL@{CI\_\-FILESENDCANCEL}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4ad3d543e05399f24d0e3aa51125bfe256}{
CI\_\-FILESENDCANCEL}
\label{class_connection_acea45320bf437182b6df56d238f127d4ad3d543e05399f24d0e3aa51125bfe256}
}]文件取消发送 \index{CI\_\-FILECONTENT@{CI\_\-FILECONTENT}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILECONTENT@{CI\_\-FILECONTENT}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4aa0369367db1b811c01bce029a8f47d2a}{
CI\_\-FILECONTENT}
\label{class_connection_acea45320bf437182b6df56d238f127d4aa0369367db1b811c01bce029a8f47d2a}
}]文件内容 \index{CI\_\-FILECLOSE@{CI\_\-FILECLOSE}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILECLOSE@{CI\_\-FILECLOSE}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4ab1b973f17f2c75ba75ba03fbd5ba5ccc}{
CI\_\-FILECLOSE}
\label{class_connection_acea45320bf437182b6df56d238f127d4ab1b973f17f2c75ba75ba03fbd5ba5ccc}
}]文件关闭 \index{CI\_\-FILEMD5@{CI\_\-FILEMD5}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILEMD5@{CI\_\-FILEMD5}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4a42c1f798607deead31db115c4a382b59}{
CI\_\-FILEMD5}
\label{class_connection_acea45320bf437182b6df56d238f127d4a42c1f798607deead31db115c4a382b59}
}]文件MD5请求 \index{CI\_\-FILEEND@{CI\_\-FILEEND}!Connection@{Connection}}\index{Connection@{Connection}!CI\_\-FILEEND@{CI\_\-FILEEND}}\item[{\em 
\hypertarget{class_connection_acea45320bf437182b6df56d238f127d4a26d0ecb83471911a4f52faebbdca9da7}{
CI\_\-FILEEND}
\label{class_connection_acea45320bf437182b6df56d238f127d4a26d0ecb83471911a4f52faebbdca9da7}
}]文件结束 \end{description}
\end{Desc}



\subsection{构造及析构函数文档}
\hypertarget{class_connection_a9de94289ca6259f94ef6aeba3b134a77}{
\index{Connection@{Connection}!Connection@{Connection}}
\index{Connection@{Connection}!Connection@{Connection}}
\subsubsection[{Connection}]{\setlength{\rightskip}{0pt plus 5cm}Connection::Connection (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a9de94289ca6259f94ef6aeba3b134a77}
构造空的Connection对象 \hypertarget{class_connection_ac5af327d034a807cbdd45cd93b8d4efc}{
\index{Connection@{Connection}!Connection@{Connection}}
\index{Connection@{Connection}!Connection@{Connection}}
\subsubsection[{Connection}]{\setlength{\rightskip}{0pt plus 5cm}Connection::Connection (
\begin{DoxyParamCaption}
\item[{const SOCKADDR\_\-IN \&}]{newAddr, }
\item[{int}]{newRecvfd = {\ttfamily 0}}
\end{DoxyParamCaption}
)}}
\label{class_connection_ac5af327d034a807cbdd45cd93b8d4efc}
构造Connection对象 
\begin{DoxyParams}{参数}
{\em const} & SOCKADDR\_\-IN \& 地址 \\
\hline
{\em int} & 接受套接字 \\
\hline
\end{DoxyParams}
\hypertarget{class_connection_a2e4352edf667bea83001569e9da8a24d}{
\index{Connection@{Connection}!$\sim$Connection@{$\sim$Connection}}
\index{$\sim$Connection@{$\sim$Connection}!Connection@{Connection}}
\subsubsection[{$\sim$Connection}]{\setlength{\rightskip}{0pt plus 5cm}Connection::$\sim$Connection (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a2e4352edf667bea83001569e9da8a24d}
析构Connection对象 

\subsection{成员函数文档}
\hypertarget{class_connection_a02edd03264480bcfec195f88c65385c5}{
\index{Connection@{Connection}!addFileToSend@{addFileToSend}}
\index{addFileToSend@{addFileToSend}!Connection@{Connection}}
\subsubsection[{addFileToSend}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::addFileToSend (
\begin{DoxyParamCaption}
\item[{const std::string \&}]{filepath}
\end{DoxyParamCaption}
)}}
\label{class_connection_a02edd03264480bcfec195f88c65385c5}
创建新的文件状态至发送列表，等待发送 
\begin{DoxyParams}{参数}
{\em string} & 文件路径 \\
\hline
\end{DoxyParams}


Bug: 无法重复发送一个文件或者发送后缀名为空的文件 fix：将send()函数放到map.insert()之后，可能本地的map并未创立 但是已经开始发送了，本地状态始终为FS\_\-WAIT=0. fix by Olin

\hypertarget{class_connection_a4dbf656f9bb517b2effa9d40ff49eabd}{
\index{Connection@{Connection}!closeCon@{closeCon}}
\index{closeCon@{closeCon}!Connection@{Connection}}
\subsubsection[{closeCon}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::closeCon (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a4dbf656f9bb517b2effa9d40ff49eabd}
关闭连接并重置状态 \hypertarget{class_connection_a6338a92b3fc9db9d1c82f537aecd1c10}{
\index{Connection@{Connection}!compare@{compare}}
\index{compare@{compare}!Connection@{Connection}}
\subsubsection[{compare}]{\setlength{\rightskip}{0pt plus 5cm}bool Connection::compare (
\begin{DoxyParamCaption}
\item[{const {\bf Connection} \&}]{cpCon}
\end{DoxyParamCaption}
)}}
\label{class_connection_a6338a92b3fc9db9d1c82f537aecd1c10}
比较对象是否相同 
\begin{DoxyRetVals}{返回值}
{\em bool} & true 相同 \\
\hline
{\em bool} & false 不相同 \\
\hline
\end{DoxyRetVals}
\hypertarget{class_connection_a2ce3e68b2f6e09a86591b3fc8818fac3}{
\index{Connection@{Connection}!getRecvfd@{getRecvfd}}
\index{getRecvfd@{getRecvfd}!Connection@{Connection}}
\subsubsection[{getRecvfd}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::getRecvfd (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a2ce3e68b2f6e09a86591b3fc8818fac3}
获取接收套接字 
\begin{DoxyRetVals}{返回值}
{\em int} & 接收套接字 \\
\hline
\end{DoxyRetVals}
\hypertarget{class_connection_a3c590179abcedd53b3bae4fd3046a374}{
\index{Connection@{Connection}!getSelfAddr@{getSelfAddr}}
\index{getSelfAddr@{getSelfAddr}!Connection@{Connection}}
\subsubsection[{getSelfAddr}]{\setlength{\rightskip}{0pt plus 5cm}SOCKADDR\_\-IN Connection::getSelfAddr (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a3c590179abcedd53b3bae4fd3046a374}
获取本对象所对应的地址 
\begin{DoxyRetVals}{返回值}
{\em SOCKADDR\_\-IN} & 对象地址信息 \\
\hline
\end{DoxyRetVals}
\hypertarget{class_connection_ac8c5ffaeee6b7ac1ac3b4eb27a1f6193}{
\index{Connection@{Connection}!isExist@{isExist}}
\index{isExist@{isExist}!Connection@{Connection}}
\subsubsection[{isExist}]{\setlength{\rightskip}{0pt plus 5cm}bool Connection::isExist (
\begin{DoxyParamCaption}
\item[{const SOCKADDR\_\-IN \&}]{cpAddr}
\end{DoxyParamCaption}
)}}
\label{class_connection_ac8c5ffaeee6b7ac1ac3b4eb27a1f6193}
判断对象是否已经被创建 
\begin{DoxyParams}{参数}
{\em const} & SOCKADDR\_\-IN \& 对象比较地址\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em bool} & true 相同 \\
\hline
{\em bool} & false 不相同 \\
\hline
\end{DoxyRetVals}
\hypertarget{class_connection_a6fa2bc6d6be7049487cce4135c3657e6}{
\index{Connection@{Connection}!sendMsg@{sendMsg}}
\index{sendMsg@{sendMsg}!Connection@{Connection}}
\subsubsection[{sendMsg}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::sendMsg (
\begin{DoxyParamCaption}
\item[{const std::string}]{msg}
\end{DoxyParamCaption}
)}}
\label{class_connection_a6fa2bc6d6be7049487cce4135c3657e6}
发送消息 
\begin{DoxyParams}{参数}
{\em string} & 消息内容 \\
\hline
\end{DoxyParams}
\hypertarget{class_connection_a76abdfdf3ba06bb8bfbc95d8cc3e9d8b}{
\index{Connection@{Connection}!setRecvfd@{setRecvfd}}
\index{setRecvfd@{setRecvfd}!Connection@{Connection}}
\subsubsection[{setRecvfd}]{\setlength{\rightskip}{0pt plus 5cm}void Connection::setRecvfd (
\begin{DoxyParamCaption}
\item[{int}]{newRecvfd}
\end{DoxyParamCaption}
)}}
\label{class_connection_a76abdfdf3ba06bb8bfbc95d8cc3e9d8b}
设置接收套接字 
\begin{DoxyParams}{参数}
{\em int} & 新的接收套接字 \\
\hline
\end{DoxyParams}
\hypertarget{class_connection_a3c0a490cbc7337b7dda84ef72f3b5632}{
\index{Connection@{Connection}!startCon@{startCon}}
\index{startCon@{startCon}!Connection@{Connection}}
\subsubsection[{startCon}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::startCon (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a3c0a490cbc7337b7dda84ef72f3b5632}
开始连接 \hypertarget{class_connection_a34ff84664e4b728d4f59947dd45788a2}{
\index{Connection@{Connection}!testConnect@{testConnect}}
\index{testConnect@{testConnect}!Connection@{Connection}}
\subsubsection[{testConnect}]{\setlength{\rightskip}{0pt plus 5cm}int Connection::testConnect (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}
\label{class_connection_a34ff84664e4b728d4f59947dd45788a2}
测试用函数 \hypertarget{class_connection_a9f3f51055f4c70eeef82a7ba68e85e97}{
\index{Connection@{Connection}!thread\_\-recv@{thread\_\-recv}}
\index{thread\_\-recv@{thread\_\-recv}!Connection@{Connection}}
\subsubsection[{thread\_\-recv}]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ Connection::thread\_\-recv (
\begin{DoxyParamCaption}
\item[{void $\ast$}]{arg}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}static\mbox{]}}}}
\label{class_connection_a9f3f51055f4c70eeef82a7ba68e85e97}
监听线程函数，当连接有效时创建 \hypertarget{class_connection_a3f7349a98ae89d34f50dfbe839e14a13}{
\index{Connection@{Connection}!thread\_\-sendfile@{thread\_\-sendfile}}
\index{thread\_\-sendfile@{thread\_\-sendfile}!Connection@{Connection}}
\subsubsection[{thread\_\-sendfile}]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ Connection::thread\_\-sendfile (
\begin{DoxyParamCaption}
\item[{void $\ast$}]{arg}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}static\mbox{]}}}}
\label{class_connection_a3f7349a98ae89d34f50dfbe839e14a13}
发送文件线程，在发送列表非空时创建 

该类的文档由以下文件生成：\begin{DoxyCompactItemize}
\item 
E:/CODE/CPPpro/cute-\/transfer/Msg\&FileTransfer/connection.h\item 
E:/CODE/CPPpro/cute-\/transfer/Msg\&FileTransfer/connection.cpp\end{DoxyCompactItemize}
